package com.x.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * ClassName: ServiceJavaConfig
 * Package: IntelliJ IDEA
 * Description:
 * 业务层配置类
 *      1、开启Aop注解的支持
 *          如 @Before @After @AfterReturning @AfterThrowing @Around
 *      2、tx声明式事务管理
 *          （1）对应事务管理器
 *          （2）开始事务注解
 *          （3）Transactional
 * Written by HanXu
 * Create 2024.09.15 15:01
 */

@Configuration
@EnableAspectJAutoProxy //开启Aop注解的支持
@EnableTransactionManagement //开启事务注解的支持
@ComponentScan("com.x")
public class ServiceJavaConfig {
    @Bean
    public TransactionManager transactionManager(DataSource dataSource){
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}
